<?php
namespace core\models;
/**
 * 常用小工具类。
 * 如：检测手机号、电子邮箱、电话号码等
 * Class Tools
 * @package core\models
 * @author  ZhouHaoHua <53027327@qq.com>
 * @package
 */
class Tools {
    /**
     * 检测是否是手机号码
     * @param string $number 待检测的号码
     * @return bool
     * @author ZhouHaoHua <53027327@qq.com>
     */
    public function isMobilePhone($number) {
        if (!is_numeric($number)) {
            return false;
        }
        return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $number) ? true : false;
    }

    /**
     * 检测当前客户端是否是手机端
     * @return bool
     * @author ZhouHaoHua <53027327@qq.com>
     */
    public function isMobileSystem() {
        $agent = $_SERVER['HTTP_USER_AGENT'];
        if (stripos($agent, "NetFront") || stripos($agent, "iPhone") || stripos($agent, "MIDP-2.0") ||
            stripos($agent, "Opera Mini") || stripos($agent, "UCWEB") || stripos($agent, "Android") ||
            stripos($agent, "Windows CE") || stripos($agent, "iemobile") || stripos($agent, "SymbianOS")
        ) {
            return true;
        }
        return false;
    }

    /**
     * 检测是否是电子邮箱
     * @param string $email 待检测的邮箱
     * @return bool
     * @author ZhouHaoHua <53027327@qq.com>
     */
    public function isEmail($email) {
        if(filter_var($email, FILTER_VALIDATE_EMAIL)){
            return true;
        }
        return false;
    }
}